package lambdademo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 74646
 * Date: 2022-03-31
 * Time: 22:44
 */


//@FunctionalInterface
//上面这个注解用于修饰NoParameterNoReturn这个接口，证明这个接口是一个函数式接口
//函数式接口只能有一个抽象方法
//interface NoParameterNoReturn{
//    void test();
//}


//有一个参数，无返回值
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}

//有多个参数，无返回值
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a, int b);
}

//有返回值，无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}

//有返回值，有一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}

//有返回值，有多个参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a, int b);
}

public class TestDemo {
    public static void main(String[] args) {
        MoreParameterReturn moreParameterReturn1 = (a,b)->{
            return a+b;
        };
        int ret = moreParameterReturn1.test(10,20);
        System.out.println(ret);

        //简写1
        MoreParameterReturn moreParameterReturn2 = (a,b)->a+b;
        System.out.println(moreParameterReturn2.test(60, 60));

        //简写2
        MoreParameterReturn moreParameterReturn3 = Integer::sum;
        System.out.println(moreParameterReturn3.test(80, 100));
    }

    public static void main6(String[] args) {
        OneParameterReturn oneParameterReturn1 = (a)->{
            return a+10;
        };
        int ret = oneParameterReturn1.test(10);
        System.out.println(ret);

        //简写
        OneParameterReturn oneParameterReturn2 = a->a+11;
        System.out.println(oneParameterReturn2.test(22));
    }


    public static void main5(String[] args) {
        NoParameterReturn noParameterReturn1 = ()->{return 10;};
        int ret = noParameterReturn1.test();
        System.out.println(ret);

        //简写
        NoParameterReturn noParameterReturn2 = ()->50;
        System.out.println(noParameterReturn2.test());
    }




    public static void main4(String[] args) {
        MoreParameterNoReturn moreParameterNoReturn1 = (int a,int b)->{
            System.out.println(a+b);
        };
        moreParameterNoReturn1.test(10,20);

        //简写
        MoreParameterNoReturn moreParameterNoReturn2 = (a,b)-> System.out.println(a+b);
        moreParameterNoReturn2.test(50,100);
    }

    public static void main3(String[] args) {
//        OneParameterNoReturn oneParameterNoReturn = (a) -> { System.out.println(a); };
        OneParameterNoReturn oneParameterNoReturn1 = a ->  System.out.println(a);
        OneParameterNoReturn oneParameterNoReturn2 = System.out::println;
        oneParameterNoReturn1.test(50);
        oneParameterNoReturn2.test(100);
    }


    public static void main2(String[] args) {
        NoParameterNoReturn noParameterNoReturn = ()-> System.out.println("重写test方法");
        noParameterNoReturn.test();
    }

    public static void main1(String[] args) {
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn(){
            @Override
            public void test() {
                System.out.println("重写test方法");
            }
        };
        //调用test方法
        noParameterNoReturn.test();
    }
}
